package com.shop.admin.controller;

import com.shop.admin.entity.SysMenu;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.SysMenuService;
import com.shop.admin.vo.RoleMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"SysRoleMenuController"},description = "角色菜单接口")
@RestController
@RequestMapping("/api/menu")
public class SysRoleMenuController {

    @Resource
    private SysMenuService sysMenuService;

    //菜单列表（树形）
    @ApiOperation("菜单列表")
    @GetMapping("/tree")
    public ApiResult findNodes() {
        List<SysMenu> list = sysMenuService.findNodes();
        return ApiResult.ok(list);
    }

    @ApiOperation("给角色分配菜单权限")
    @PostMapping("/doAssign")
    public ApiResult doAssign(@RequestBody RoleMenuVo roleMenuVo) {
        sysMenuService.doAssign(roleMenuVo);
        return ApiResult.ok("分配成功!");
    }

    //根据角色分配菜单
    @ApiOperation("根据角色获取菜单")
    @GetMapping("/toAssign/{roleId}")
    public ApiResult toAssign(@PathVariable String roleId) {
        List<SysMenu> list = sysMenuService.findMenuByRoleId(roleId);
        return ApiResult.ok(list);
    }

}
